<template>
	<Layout>
		<div>
			<span style="width:63px;height:17px;font-size:16px;font-family:Microsoft YaHei;
                         font-weight:400;margin-right:50px;margin-left: 15px;
                         color:rgba(41,82,159,0.91);
                         line-height:46px;">案例库</span>
			<Button v-if="parentFlag" size="large" type="success" class="ivu-btn-save" style="margin-bottom: 10px;margin-right: 13px"
			 @click="addParentFlag = true">新增</Button>
			<hr />
		</div>
		<div class="demo-split">
			<Split v-model="split">
				<div slot="left" class="demo-split-pane">
					<div style="height: 100%;overflow-y: auto;overflow-x:hidden;background-color:#FFF;">
						<Tree :expand-node='true' :expand='true' :selected='true' :style="{backgroundColor:'#FFF'}" :data="listData"
						 :load-data="loadListData" :render="renderContent">
						</Tree>
						<Dropdown trigger="click" style="margin-left:20px" placement="right-start" ref="contentMenu" @on-click="selectMenuItem">
							<DropdownMenu slot="list">
								<Dropdown placement="right-start">
									<Dropdown-item>新增目录<i class="ivu-icon ivu-icon-ios-arrow-forward"></i>
									</Dropdown-item>
									<Dropdown-menu slot="list">
										<Dropdown-item name="addPoint">新增目录</Dropdown-item>
										<Dropdown-item name="editPoint">修改目录</Dropdown-item>
										<Dropdown-item name="deletePoint">删除目录</Dropdown-item>
									</Dropdown-menu>
								</Dropdown>
								<DropdownItem name="addIssuesData">添加案例</dropdownitem>
							</dropdownmenu>
						</Dropdown>
						<!-- <Dropdown trigger="click" style="margin-left:20px" placement="right-start" ref="contentMenu" @on-click="selectMenuItem">
							<DropdownMenu slot="list">
								<DropdownItem name="addPoint">新增目录</dropdownitem>
								<DropdownItem name="editPoint">修改目录</dropdownitem>
								<DropdownItem name="deletePoint">删除目录</dropdownitem>
								<DropdownItem name="addIssuesData">添加案例</dropdownitem>
							</dropdownmenu>
						</Dropdown> -->
					</div>
				</div>
				<!--右侧div添加列表-->
				<div slot="right" class="demo-split-pane">
					<div style="height:100%" class="modelSub">
						<Table :height="tableHeight" :loading="loading" size="small" class="table" no-data-text="没有查询到相关数据!" border
						 :columns="columns2" :data="selectedDataTable" @on-selection-change="handleSelectRow">
						</Table>
						<Row style="margin-right:10px;">
							<Col span="24">
							<Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" style="float: right"
							 @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
							</Col>
						</Row>
					</div>
				</div>
			</Split>
		</div>
		<!--首次-->
		<Modal :transfer='false' v-model="addParentFlag" :width=600 style="display: flex; align-items: center; justify-content: center;">
			<Form ref="listFormData" :model="listFormData" :rules="listRuleValidate" :label-width="160">
				<Row>
					<Col span="20">
					<FormItem label="目录名称:" prop="issuesName">
						<Input type="text" v-model="listFormData.issuesName"></Input>
					</FormItem>
					</Col>
				</Row>
			</Form>
			<div slot="footer">
				<Button type="primary" class='ivu-btn-save' @click="saveListData()">保存</Button>
				<Button type="primary" class='ivu-btn-cancel' @click="handleListCancel" style="margin-left: 2px">取消</Button>
			</div>
		</Modal>
		<!--添加树-->
		<Modal :transfer='false' v-model="listModel" :width=600 style="display: flex; align-items: center; justify-content: center;">
			<Form ref="listFormData" :model="listFormData" :rules="listRuleValidate" :label-width="160">
				<Row v-if="listFormData.parentName != ''">
					<Col span="20">
					<FormItem label="上级目录名称:" prop="parentName">
						<Input v-model="listFormData.parentName" :readonly="true" disabled></Input>
					</FormItem>
					</Col>
				</Row>
				<Row v-if="listFormData.id != ''">
					<Col span="20">
					<FormItem label="序号:" prop="seq">
						<Input v-model="listFormData.seq"></Input>
					</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span="20">
					<FormItem label="目录名称:" prop="issuesName">
						<Input type="text" v-model="listFormData.issuesName"></Input>
					</FormItem>
					</Col>
				</Row>
			</Form>
			<div slot="footer">
				<Button type="primary" class='ivu-btn-save' @click="saveListData()">保存</Button>
				<Button type="primary" class='ivu-btn-cancel' @click="handleListCancel" style="margin-left: 2px">取消</Button>
			</div>
		</Modal>
		<!--添加数据列表-->
		<Modal title="安全事故案例" :transfer='false' v-model="dataListModel" :width='1200'>
			<Row>
				<Form ref="form1" :model="form1" :label-width="120">
					<Row v-show="!switchFlag" class="query-form" style="padding-top: 15px">
						<Col span="8">
						<FormItem label="伤害程度：">
							<Select v-model="injuryLevels" multiple>
								<Option v-for="item in injuryLeveList" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName  }}</Option>
							</Select>
						</FormItem>
						</Col>
						<Col span="8">
						<FormItem label="事故时间：">
							<DatePicker class="query-form-el" v-model="sartDateQuery" format="yyyy-MM-dd" type="daterange" placement="bottom-end"
							 @on-change="(date) => onSelectFieldQueryDateRange(date, 'sartDate')" style="width: 100%;"></DatePicker>
						</FormItem>
						</Col>
						<Col span="8">
						<Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
						<Button @click="reset" class="ivu-btn-reset">重置</Button>
						<Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
						</Col>
					</Row>
					<Row v-show="switchFlag" class="query-form" style="padding-top: 15px">
						<Col span="8">
						<FormItem label="伤害程度：">
							<Select v-model="injuryLevels" multiple>
								<Option v-for="item in injuryLeveList" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName  }}</Option>
							</Select>
						</FormItem>
						</Col>
						<Col span="8">
						<FormItem label="事故时间：">
							<DatePicker class="query-form-el" v-model="sartDateQuery" format="yyyy-MM-dd" type="daterange" placement="bottom-end"
							 @on-change="(date) => onSelectFieldQueryDateRange(date, 'sartDate')" style="width: 100%;"></DatePicker>
						</FormItem>
						</Col>
						<Col span="8">
						<FormItem label="事故类别：">
							<Select v-model="form1.accTypeId">
								<Option v-for="item in typeList" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName  }}</Option>
							</Select>
						</FormItem>
						</Col>
					</Row>
					<Row v-show="switchFlag" class="query-form" style="padding-top: 15px">
						<Col span="8">
						<FormItem label="上报单位：">
							<Input type="text" v-model="form1.orgName"></Input>
						</FormItem>
						</Col>
						<Col span="8">
						<FormItem label="就业类型：">
							<Select v-model="memberships" multiple>
								<Option v-for="item in membershipList" :value="item.codingCodeId" :key="item.codingCodeId">{{item.codingName}}</Option>
							</Select>
						</FormItem>
						</Col>

						<Col span="8">
						<Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
						<Button @click="reset" class="ivu-btn-reset">重置</Button>
						<Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
						</Col>
					</Row>
				</Form>
				<Table ref='table' :height="tableHeight" :loading="loading" size="small" class="table" no-data-text="没有查询到相关数据!"
				 border :columns="columns1" :data="dataTable" @on-selection-change="handleSelectRow">
				</Table>
			</Row>
			<div slot="footer">
				<Button @click="saveSelectAll()" class="ivu-btn-save" :loading="buttonLoading">确定</Button>
				<Button @click="onCancel" class="ivu-btn-cancel">取消</Button>
			</div>
		</Modal>

		<Modal :transfer='false' v-model="model3" :width='700' title="安全事故案例详情" :styles="{height:'500px'}" @on-cancel="onCancel"
		 class-name='limit-height-dialog'>
			<Form :model="InputData" label-position="top">
				<Row style="line-height: 42px;margin-left: 20px">
					<Row>
						<Col span='23'>
						<span>上报单位：{{InputData.orgName}}</span>
						</Col>
					</Row>
					<Row class="detail-background-clor">

						<Col span='11'>
						<span>伤亡人员姓名：{{InputData.victim}}</span>
						</Col>
						<Col span='11' offset="1">
						<span>性别：{{InputData.gender === '0'?'男':'女'}}</span>
						</Col>
					</Row>
					<Row>
						<Col span='11'>
						<span>年龄：{{InputData.age}}</span>
						</Col>
						<Col span='11' offset="1">
						<span>工种或岗位：{{InputData.position}}</span>
						</Col>
					</Row>
					<Row class="detail-background-clor">
						<Col span='11'>
						<span>伤害部位：{{InputData.injured}}</span>
						</Col>
						<Col span='11' offset="1">
						<span>事故时间：{{formatDate(new Date(InputData.sartDate), 'yyyy-MM-dd')}}</span>
						</Col>
					</Row>
					<Row>
						<Col span='11'>
						<span>事故类别：{{InputData.accTypeName}}</span>
						</Col>
						<Col span='11' offset="1">
						<span>就业类型：{{InputData.membershipName}}</span>
						</Col>
					</Row>
					<Row class="detail-background-clor">
						<Col span='11'>
						<span>伤害程度：{{InputData.injuryLevelName}}</span>
						</Col>
						<Col span='11' offset="1">
						<span>歇工天数：{{InputData.daysWork}}</span>
						</Col>
					</Row>
					<Row class="detail-background-clor">
						<Col span='11'>
						<span>上报人：{{InputData.userName}}</span>
						</Col>
						<Col span='11' offset="1">
						<span>上报时间：{{formatDate(new Date(InputData.createDate), 'yyyy-MM-dd')}}</span>
						</Col>
					</Row>

					<Row>
						<Col span='11'>
						<span>企业负责人：{{InputData.charge}}</span>
						</Col>
						<Col span='11' offset="1">
						<span>二级集团安全环保管理人员：{{InputData.secondaryGroupPersion}}</span>
						</Col>
					</Row>
					<Row class="detail-background-clor">
						<Col span='23'>
						<span>集团安全环保管理人员：{{InputData.groupPersion}}</span>
						</Col>

					</Row>
					<Row>
						<Col span='11'>
						<span>直接经济损失(万元)：{{InputData.loseMoney}}</span>
						</Col>
					</Row>


					<Row>
						<Col span='23'>
						<span>初步原因分析：{{InputData.accAnalyze}}</span>
						</Col>
					</Row>
					<Row class="detail-background-clor">
						<Col span='23'>
						<span>主要经过：{{InputData.accDesc}}</span>
						</Col>
					</Row>
					<Row>
						<Col span='23'>
						<span>备注：{{InputData.notes}}</span>
						</Col>
					</Row>
					<Row class="detail-background-clor">
						<Col span="23">
						<FormItem label="伤亡事故简报表：">
							<div v-show="uploadList.length>0" v-for="item in uploadList" :key='item.index'>
								<a @click="downloadFile(InputData.briefId,item)">{{ item.fileName }}</a>
							</div>
						</FormItem>
						</Col>
					</Row>
				</Row>
			</Form>
			<div slot="footer">
				<Button class='ivu-btn-save' @click="onCancel">关闭</Button>
			</div>
		</Modal>
	</Layout>
</template>
<script>
	import {
		sessionStorage
	} from '../../../common/cacheUtils.js';
	import {
		Api
	} from '../../../api/index.js'
	import pageCommonFunction from '@/components/pageCommonFunction.js'
	import Vue from 'vue'
	export default {
		data: function() {
			return {
				initialValue: {}, //初始节点
				parentFlag: false, //是否有顶级节点
				addParentFlag: false, //添加顶级节点
				split: 0.35,
				listModel: false,
				dataListModel: false,
				listSeq: '',
				buttonLoading: false,
				listData: [],
				listFormData: {
					id: '',
					issuesName: '',
					parentId: '',
					parentName: '',
					seq: null
				},
				listRuleValidate: {
					issuesName: [{
						required: true,
						message: '请输入!',
						trigger: 'blur'
					}]
				},
				currentNode: null, //当前操作的节点
				parentNode: null,
				selectIds: [],
				issuesId: "",
				briefId: [],
				selectedDataTable: [],
				dataToQuery: {},
				columns2: [
					// {
					// 	type: 'selection',
					// 	width: 60,
					// 	align: 'center',
					// 	fixed: 'left',
					// },
					{
						title: "序号",
						width: 80,
						align: "center",
						fixed: 'left',
						render: (h, params) => {
							return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
						}
					},
					{
						title: '状态',
						align: 'center',
						key: 'status',
						width: 100,
						render: (h, params) => {
							let color = 'green';
							if (params.row.procinstState == undefined || params.row.procinstState == null || params.row.procinstState ==
								2) {
								color = 'red';
							}
							return h('div', [
								h('span', {
										style: {
											color: color
										}
									}, params.row.procinstState == 1 ? '审批中' : params.row.procinstState == 2 ? '被退回' : params.row.procinstState ==
									3 ? '审批通过' : '未上报' || '--')
							]);
						}
					},

					{
						title: '伤亡人员姓名',
						align: 'center',
						key: 'victim',
						minWidth: 150,

					},
					{
						title: '伤害程度',
						align: 'center',
						key: 'injuryLevelName',
						minWidth: 200,

					},
					{
						title: '歇工天数',
						align: 'center',
						key: 'daysWork',
						minWidth: 150,

					},
					{
						title: '直接经济损失(万元)',
						align: 'center',
						key: 'loseMoney',
						minWidth: 150,

					},
					{
						title: '工种或岗位',
						align: 'center',
						key: 'position',
						minWidth: 150,

					},
					{
						title: '事故时间',
						align: 'center',
						key: 'sartDateStr',
						minWidth: 150,
					},
					{
						title: '事故类别',
						align: 'center',
						key: 'accTypeName',
						minWidth: 150,

					},
					{
						title: '就业类型',
						align: 'center',
						key: 'membershipName',
						minWidth: 150,

					},
					{
						title: '上报单位',
						align: 'center',
						key: 'orgName',
						minWidth: 300,
						ellipsis: true

					},
					{
						title: '操作',
						key: 'action',
						fixed: 'right',
						width: 150,
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h('A', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										fontSize: '14px',
									},
									on: {
										click: () => {
											this.InputData = JSON.parse(JSON.stringify(params.row));
											this.getFiles()
											this.model3 = true;
										}
									}
								}, '详情'), h('Divider', {
									props: {
										type: 'vertical',
									}
								}, ''),
								h('A', {
									props: {
										type: 'error',
										size: 'small'
									},
									style: {
										fontSize: '14px',
										// color: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? '#d0d0d0' : params.row.createUserId == sessionStorage('userId').getObject('userId').userId ||  this.Common.userIdList.includes(sessionStorage('userId').getObject('userId').userId ) ? 'red':'#d0d0d0',
										// pointerEvents: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? 'none' : params.row.createUserId == sessionStorage('userId').getObject('userId').userId ||  this.Common.userIdList.includes(sessionStorage('userId').getObject('userId').userId ) ? '' : 'none'
									},
									on: {
										click: () => {
											this.$Modal.confirm({
												title: '提示',
												content: '<p>是否要删除？</p>',
												onOk: () => {
													this.deleteBriefData(params.row.id);
												},
												onCancel: () => {}
											});

										}
									}
								}, '删除')
							]);
						}
					}
				],

				sartDateQuery: [],
				daysWork: false,
				uploadList: [],
				tableHeight: 10,
				loading: true,
				form1: {
					admittanceOrg: '',
					contractorName: '',
				},
				injuryLevels: [],
				memberships: [],
				sexList: [{
						value: '0',
						text: '男'
					},
					{
						value: '1',
						text: '女'
					}
				],
				pageSizeArray: [10, 20, 50],
				pagedata: {
					total: 0,
					pageSize: 10,
					currentPage: 1,
				},
				dataTable: [],
				columns1: [{
						type: 'selection',
						width: 60,
						align: 'center',
						fixed: 'left',
					},
					{
						title: "序号",
						width: 80,
						align: "center",
						render: (h, params) => {
							return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
						}
					},
					{
						title: '状态',
						align: 'center',
						key: 'status',
						width: 100,
						render: (h, params) => {
							let color = 'green';
							if (params.row.procinstState == undefined || params.row.procinstState == null || params.row.procinstState ==
								2) {
								color = 'red';
							}
							return h('div', [
								h('span', {
										style: {
											color: color
										}
									}, params.row.procinstState == 1 ? '审批中' : params.row.procinstState == 2 ? '被退回' : params.row.procinstState ==
									3 ? '审批通过' : '未上报' || '--')
							]);
						}
					},

					{
						title: '伤亡人员姓名',
						align: 'center',
						key: 'victim',
						minWidth: 150,

					},
					{
						title: '伤害程度',
						align: 'center',
						key: 'injuryLevelName',
						minWidth: 200,

					},
					{
						title: '歇工天数',
						align: 'center',
						key: 'daysWork',
						minWidth: 150,

					},
					{
						title: '直接经济损失(万元)',
						align: 'center',
						key: 'loseMoney',
						minWidth: 150,

					},
					{
						title: '工种或岗位',
						align: 'center',
						key: 'position',
						minWidth: 150,

					},
					{
						title: '事故时间',
						align: 'center',
						key: 'sartDateStr',
						minWidth: 150,
					},
					{
						title: '事故类别',
						align: 'center',
						key: 'accTypeName',
						minWidth: 150,

					},
					{
						title: '就业类型',
						align: 'center',
						key: 'membershipName',
						minWidth: 150,

					},
					{
						title: '上报单位',
						align: 'center',
						key: 'orgName',
						minWidth: 300,
						ellipsis: true

					},
					{
						title: '操作',
						key: 'action',
						fixed: 'right',
						width: 100,
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h('A', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										fontSize: '14px',
									},
									on: {
										click: () => {
											this.InputData = JSON.parse(JSON.stringify(params.row));
											this.getFiles()
											this.model3 = true;
										}
									}
								}, '详情')
							]);
						}
					}
				],
				imgUrl: "",
				switchFlag: false,
				add: false,
				InputData: {},
				banStart: '',
				banEnd: '',
				pageModel2: {
					total: 0,
					pageSize: 10,
					currentPage: 1,
					contractorName: ''
				},
				contractor: [],
				model2: false,
				model1: false,
				model3: false,
				membershipList: [],
				typeList: [],
				injuryLeveList: [],
				fileUrl: Api.interestedPartiesUserFile,
				groupPersionList: [],
				secondaryGroupPersionList: [],
				chargeList: [],
				history: [],
				model4: false,
				loading2: false,
			}
		},
		mounted: function() {
			this.getParentItem();
			this.initListTreeData();

			this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
			//企业负责人
			this.$http.get(Api.queryRoleUser + "/" + "cfb951f2448f44a6ba805e1d5313fa75", {
				params: {
					orgId: sessionStorage('userId').getObject('userId').companyId
				}
			}).then((res) => {
				this.chargeList = res.data.data;
			}).catch(e => {
				this.$Message.error("数据获取失败")
			});
			//二级集团
			this.$http.get(Api.queryRoleUser + "/" + "843197356dd443d099542d7ebe22b2be", {
				params: {
					orgId: sessionStorage('userId').getObject('userId').twoLevelOrgId,
					two: true
				}
			}).then((res) => {
				this.secondaryGroupPersionList = res.data.data;
			}).catch(e => {
				this.$Message.error("数据获取失败")
			});
			//集团
			this.$http.get(Api.queryRoleUser + "/" + "17744170d3c24383bd283fbe72f3d664").then((res) => {
				this.groupPersionList = res.data.data;
			}).catch(e => {
				this.$Message.error("数据获取失败")
			});
			this.query()
			this.selectCodingSort();
		},
		methods: {
			//判断顶级节点是否存在
			getParentItem() {
				this.$http.get(Api.getParentItem).then((res) => {
					if (res.data.data.data == null) {
						this.parentFlag = true;
					}
				}, function() {
					_this.$Message.info('获取信息失败');
				});
			},
			goBack() {
				this.$router.back();
			},
			initListTreeData() {
				let _this = this;
				let data = {
					parentId: "-1",
					orgId: sessionStorage('userId').getObject('userId').companyId
				}
				this.$http.get(Api.getSecurityIssuesByParentId, {
					params: data
				}).then((res) => {
					if (res.data != null) {
						res.data.map(node => {
							node.loading = false;
							// node.expand = true;
							node.children = [];
						})
						_this.listData = res.data;
						this.querySelectData();
					}
				}, function() {
					_this.$Message.info('获取信息失败');
				});
			},
			restListTreeData(parentId) {
				let _this = this;
				let data = {
					parentId: parentId,
					orgId: sessionStorage('userId').getObject('userId').companyId
				}
				this.$http.get(Api.getSecurityIssuesByParentId, {
					params: data
				}).then((res) => {
					if (res.data != null) {
						res.data.map(node => {
							node.loading = false;
							node.children = [];
						})
						this.querySelectData();
					}
					this.parentNode.children = res.data;
				}, function() {
					_this.$Message.info('获取信息失败');
				});
			},
			loadListData(item, callback) {
				//初始化分页
				this.initPage()
				let _this = this;
				this.issuesId = item.id
				let data = {
					parentId: item.id,
					orgId: sessionStorage('userId').getObject('userId').companyId
				}
				this.$http.get(Api.getSecurityIssuesByParentId, {
					params: data
				}).then((res) => {
					if (res.data != null) {
						res.data.map(node => {
							node.loading = false;
							node.children = [];
						})
						callback(res.data);
					}
				}, function() {
					this.$Message.info('获取机构信息失败');
				});
				this.querySelectData();
			},
			saveListData() {
				let _this = this;
				this.$refs.listFormData.validate((valid) => {
					if (valid) {
						let securityIssues = {};
						if (_this.listFormData.id == '') {
							//新增
							securityIssues = Object.assign(JSON.parse(sessionStorage('paramUserInfo').get('userInfo')), this.listFormData);
						} else {
							//修改
							securityIssues = this.listFormData;
						}
						this.$http.post(Api.saveOrUpdateIssues, securityIssues).then((res) => {

							if (res.data.result == "success") {
								_this.$Message.info("保存成功!");
								this.addParentFlag = false

								let id = res.data.id;

								if (this.listData && this.listData.length == 0) {
									this.initListTreeData()
								}
								if (_this.listFormData.id == '') {
									//以下如更新节点
									if (_this.currentNode == null) {
										_this.currentNode = {
											issuesName: _this.listFormData.issuesName,
											id: id,
											expand: true
										}
									}
									const children = _this.currentNode && _this.currentNode.children || [];
									if (children) {
										children.push({
											issuesName: _this.listFormData.issuesName,
											id: id,
											expand: true //展开子节点
										});
									}
									this.$set(_this.currentNode, 'children', children);
								} else {
									if (_this.listSeq == _this.listFormData.seq) this.$set(_this.currentNode, 'issuesName', _this.listFormData
										.issuesName);
									else _this.restListTreeData(_this.parentNode.id);
								}
							} else {
								_this.$Message.info("保存失败！");
							}
							_this.handleListCancel();
						}, function() {
							_this.$Message.info('保存失败!');
						});
					} else {
						this.$Message.error('请填报完整!');
					}
				})
			},
			handleListCancel() {
				this.listModel = false;
				this.addParentFlag = false;
			},

			renderContent(h, {
				root,
				node,
				data
			}) {
				return h('span', {
					style: {
						display: 'inline-block',
						cursor: 'pointer',
					},
					on: {
						click: () => {
							this.selectNodeInfo = data;
							this.selectNode = node;
							this.selectRoot = root;
						},
						//右键点击事件
						contextmenu: (e) => {
							e.preventDefault();
							this.selectNodeInfo = data;
							this.selectNode = node;
							this.selectRoot = root;

							this.$refs.contentMenu.$refs.reference = event.target;
							this.$refs.contentMenu.currentVisible = !this.$refs.contentMenu.currentVisible;
						},
					}
				}, [h('span', [h('Icon', {
					props: {
						type: 'ios-paper-outline'
					},
					style: {
						marginRight: '8px'
					}
				}), h('span', data.issuesName)])]);
			},

			selectMenuItem(name) {
				if (name == "addPoint") {
					this.addListData(this.selectRoot, this.selectNode, this.selectNodeInfo);
				}
				if (name == "editPoint") {
					this.toEditListData(this.selectRoot, this.selectNode, this.selectNodeInfo);
				}
				if (name == "deletePoint") {
					this.removeList(this.selectRoot, this.selectNode, this.selectNodeInfo);
				}
				if (name == "addIssuesData") {
					this.addIssuesData(this.selectRoot, this.selectNode, this.selectNodeInfo);
				}
			},
			addListData(root, node, data) {
				this.listModel = true;
				this.currentNode = data;
				this.$refs.listFormData.resetFields();
				this.listFormData = {};
				this.listFormData.id = "";
				this.listFormData.parentId = data.id;
				this.listFormData.parentName = data.issuesName == null ? '' : data.issuesName;
			},
			toEditListData(root, node, data) {
				this.currentNode = data;
				const parentKey = root.find(el => el === node).parent;
				const parent = root.find(el => el.nodeKey === parentKey).node;
				this.parentNode = parent;
				let parentName = (parent.title == '' ? "" : parent.issuesName);
				this.$http.get(Api.getSecurityIssuesById + data.id).then((res) => {
					if (res.data.securityIssues != null) {
						let securityIssues = res.data.securityIssues;
						this.listFormData.id = securityIssues.id;
						this.listFormData.issuesName = securityIssues.issuesName;
						this.listFormData.seq = securityIssues.seq;
						this.listSeq = securityIssues.seq;
						this.listFormData.parentId = securityIssues.parentId;
						this.listFormData.parentName = parentName;
						this.listModel = true;
					}
				}, function() {
					this.$Message.info('获取信息失败');
				});

			},
			removeList(root, node, data) {
				let _this = this;
				let config = {
					title: '系统提示',
					content: '确认删除此数据吗?',
					okText: '确定',
					cancelText: '取消',
					onOk: function() {
						_this.$Spin.show({
							render: (h) => {
								return h('div', [
									h('Icon', {
										'class': 'demo-spin-icon-load',
										props: {
											type: 'ios-loading',
											size: 18
										}
									}),
									h('div', 'Loading')
								])
							}
						});
						let queryData = {
							id: data.id,
							orgId: sessionStorage('userId').getObject('userId').companyId
						}
						this.$http.get(Api.deleteIssuesById, {
							params: queryData
						}).then((res) => {
							if (res.data.result == "success") {
								_this.$Message.success({
									content: '删除成功!'
								})
								const parentKey = root.find(el => el === node).parent;
								const parent = root.find(el => el.nodeKey === parentKey).node;
								const index = parent.children.indexOf(data);
								parent.children.splice(index, 1);
								if (parent.children.length == 0) {
									Vue.delete(parent, 'children')
									Vue.delete(parent, 'loading')
								}
							} else {
								_this.$Message.error({
									content: res.data.msg,
									duration: 3,
									closable: true
								})
							}
							_this.loading = false
							_this.$Spin.hide();
						}, function() {
							_this.$Spin.hide();
							_this.$Message.error('删除失败');
						});
					},
					onCancel: function() {}
				}
				this.$Modal.confirm(config);
			},
			addIssuesData(root, node, data) {
				this.dataListModel = true;
				this.issuesId = data.id
				this.query()
			},

			deleteBriefData(id) {
				this.$http.get(Api.deleteIssuesBrifeById + id).then((res) => {
					if (res.data.result == "success") {
						this.$Message.success({
							content: '删除成功!'
						})
						this.querySelectData();
					} else {
						this.$Message.error({
							content: '删除失败',
							duration: 3,
							closable: true
						})
					}
				}, function() {
					this.$Message.error('删除失败');
				});
			},

			switchQuery(flag) {
				this.switchFlag = flag;
				if (!this.switchFlag) {
					this.tableHeight = this.tableHeight + 44;
				} else {
					this.tableHeight = this.tableHeight - 44;
				}
			},
			onSelectFieldQueryDateRange(data, filed) {
				if (data[0] === "" || data[1] === "") {
					this.form1[filed + 'Start'] = null;
					this.form1[filed + 'End'] = null;
				} else {
					this.form1[filed + 'Start'] = data[0] + ' 00:00:00';
					this.form1[filed + 'End'] = data[1] + ' 23:59:59';
				}
			},

			downloadFile(guideId, file) {
				let url = this.fileUrl + '/file/' + file.id;
				this.$http.get(url, {
					responseType: 'blob' //告诉服务器我们需要的响应格式
				}).then((res) => {
					const aLink = document.createElement("a");
					let blob = new Blob([res.data], {
						type: res.bodyBlob.type //将会被放入到blob中的数组内容的MIME类型
					});
					aLink.href = URL.createObjectURL(blob)
					aLink.download = file.fileName //标题
					aLink.click()
					document.body.appendChild(aLink)
				})
			},

			formatDate(date, fmt) {
				if (/(y+)/.test(fmt)) {
					fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
				}
				let o = {
					'M+': date.getMonth() + 1,
					'd+': date.getDate(),
					'h+': date.getHours(),
					'm+': date.getMinutes(),
					's+': date.getSeconds()
				};
				for (let k in o) {
					if (new RegExp(`(${k})`).test(fmt)) {
						let str = o[k] + '';
						fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
					}
				}
				return fmt;
			},
			padLeftZero(str) {
				return ('00' + str).substr(str.length);
			},

			getFiles() {
				let url = this.fileUrl + '/' + this.InputData.briefId + '/files/guideFile'
				this.$http.get(url).then((res) => {
					if (res.data.result == "success") {
						this.uploadList = res.data.data
					}
				})
			},

			selectContractor() {
				this.model2 = true
				this.contractor = []
				let data = {
					startPage: this.pageModel2.currentPage,
					size: this.pageModel2.pageSize,
					contractorName: this.pageModel2.contractorName
				}
				data = Object.assign(data);
				let url = Api.interestedPartiesAccountList
				this.$http.get(url, {
					params: data
				}).then((res) => {
					this.contractor = res.data.data.data;
					this.pageModel2.total = res.data.data.totalSize;
				}).catch(e => {
					this.$Message.error("数据获取失败")
				})
			},

			onCancel() {
				this.InputData = {}
				this.dataListModel = false
				this.model1 = false
				this.model3 = false
				this.selectIds = []
				// this.query();
			},
			selectCodingSort() {
				this.$http.get(Api.queryCodeDetailBySortId + '/MEM-000001', {
					params: {}
				}).then((res) => {
					this.membershipList = res.data.data;
				});
				this.$http.get(Api.queryCodeDetailBySortId + '/ACC-000001', {
					params: {}
				}).then((res) => {
					this.typeList = res.data.data;
				});
				this.$http.get(Api.queryCodeDetailBySortId + '/1000001019', {
					params: {}
				}).then((res) => {
					this.injuryLeveList = res.data.data;
				});


			},


			query() {
				this.loading = true;
				let data = {
					startPage: this.pagedata.currentPage,
					size: this.pagedata.pageSize,
					orgId: sessionStorage('userId').getObject('userId').companyId,
					issuesId: this.issuesId
				};
				this.form1.injuryLevels = "";
				this.form1.memberships = "";
				this.injuryLevels.forEach(item => {
					this.form1.injuryLevels += item + ","
				});
				this.memberships.forEach(item => {
					this.form1.memberships += item + ","
				});
				data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
				let url = Api.getBriefingList
				this.$http.get(url, {
					params: data
				}).then((res) => {
					this.dataTable = res.data.data.data;
					// this.pagedata.total = res.data.data.totalSize;
					this.loading = false;
				}).catch(e => {
					this.$Message.error("数据获取失败")
				})
			},
			reset() {
				this.form1 = {
					admittanceOrg: '',
					contractorName: '',
				};
				this.injuryLevels = [];
				this.memberships = [];
				this.sartDateQuery = [];
				this.pageModel2.currentPage = 1;
				this.pageModel2.contractorName = ''
				this.query();
			},
			// pageChange1(pageNum) {
			// 	this.pageModel2.currentPage = pageNum;
			// 	this.selectContractor();
			// },
			// pageSizeChange1(pageSize) {
			// 	this.pageModel2.pageSize = pageSize;
			// 	this.selectContractor();
			// },
			pageChange(pageNum) {
				this.pagedata.currentPage = pageNum;
				this.querySelectData();
			},
			pageSizeChange(pageSize) {
				this.pagedata.pageSize = pageSize;
				this.querySelectData();
			},

			handleSelectRow() {
				this.selectIds = [];
				this.$refs.table.getSelection().map(item => {
					this.selectIds.push(item.briefId)
				})
			},
			saveSelectAll() {
				this.loading = true;
				let data = {
					selectIds: this.selectIds,
					issuesId: this.issuesId,
					orgId: sessionStorage('userId').getObject('userId').companyId
				};
				this.$http.post(Api.saveIssuesBrife, data).then(function(res) {
					this.loading = false;
					this.dataListModel = false;
					this.$Message.success({
						content: '添加成功',
						duration: 4
					});
					this.selectIds = []
					this.querySelectData();
				}, function(err) {
					this.loading = false;
					this.dataListModel = false;
					this.selectIds = []
					this.$Message.error({
						content: '添加失败',
						duration: 4
					});
				});
			},

			querySelectData() {
				this.loading = true
				let dataToQuery = {}
				dataToQuery.orgId = sessionStorage('userId').getObject('userId').companyId
				dataToQuery.issuesId = this.issuesId
				let data = {
					startPage: this.pagedata.currentPage,
					size: this.pagedata.pageSize,
					conditions: dataToQuery
				};
				this.$http.post(Api.getIssuesBrifeByIssuesId, data).then((res) => {
					if (res.data.status === 201) {
						this.$Message.error(res.data.msg);
					}
					this.selectedDataTable = res.data.data.data;
					this.pagedata.total = res.data.data.totalSize;
					this.loading = false
				}).catch(e => {
					this.$Message.error("数据获取失败")
					this.loading = false
				})
			},
			initPage() {
				//切换节点初始化分页
				this.pageSizeArray= [10, 20, 50]
				this.pagedata = {
					total: 0,
					pageSize: 10,
					currentPage: 1,
				}
			}
		},
	};
</script>
<style lang='css' scoped>
	@import '../../../index.css';

	.demo-split {
		width: 100%;
		height: 450px;
		overflow: hidden;
	}

	.demo-split-pane {
		height: 100%;
	}

	.modelSub {
		background-color: #ffffff;
		overflow-y: auto;
		overflow-x: hidden;
	}

	.modelSub .left {
		float: left;
		padding-left: 20px;
		font-size: 16px;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: rgba(51, 51, 51, 1);
		line-height: 48px;
	}

	.modelSub .right {
		margin-top: 10px;
		float: right;
	}

	.modelSub .subleft {
		float: left;
		padding-left: 20px;
		font-size: 14px;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: rgba(51, 51, 51, 1);
		line-height: 48px;
	}

	.modelSub .subright {
		float: right;
	}

	.ivu-btn-delete {
		background: #ffffff;
		height: 30px;
		border: 1px solid rgba(220, 222, 226, 1);
		border-radius: 4px;
		color: #333333;
		font-size: 14px;
		font-family: Microsoft YaHei;
		margin-top: 10px;
	}

	.ivu-btn-delete:hover {
		height: 30px;
		background: #FFFFFF;
		border: 1px solid #F27874;
		border-radius: 4px;
		font-size: 14px;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #F27874;
	}
</style>
